Skip to content

fix(logservice): close store on initialization failure#25774

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:agent/fix-logservice-init-cleanup
Jul 16, 2026
Merged

fix(logservice): close store on initialization failure#25774
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:agent/fix-logservice-init-cleanup

Conversation

@LeftHandCold

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #25740

What this PR does / why we need it:

NewService creates a live log store before loading local metadata and restoring persisted replicas. If either initialization step returned an error, the constructor returned without closing the store. The orphaned Dragonboat NodeHost kept its gossip/Raft listeners, TanDB handles, directory lock, and truncation worker alive, so an in-process retry with the same configuration failed with an address conflict.

This change closes the store on both error paths while preserving the original initialization error. The successful startup path, on-disk metadata, and RPC behavior are unchanged.

The regression tests exercise both sides of the failure window:

  • an injected metadata open error before replica restoration;
  • dragonboat.ErrShardAlreadyExist after one persisted replica has already been restored.

Each test retries construction with the same UUID, data directory, and network addresses, proving that the NodeHost, workers, listeners, and storage handles were released.

Validation (with the standard MatrixOne CGo environment):

  • go test -v -count=1 -timeout 120s -run 'TestNewServiceClosesStoreOn(Metadata|ReplicaStart)Failure$' ./pkg/logservice
  • go test -race -count=1 -timeout 180s -run 'TestNewServiceClosesStoreOn(Metadata|ReplicaStart)Failure$' ./pkg/logservice
  • go test -v -count=1 -timeout 300s ./pkg/logservice
  • go build ./pkg/logservice
  • go vet ./pkg/logservice

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-07-16 04:33 UTC · Rule: main · triggered by @LeftHandCold with the merge queue checkbox
  • Checks passed · in-place
  • Merged2026-07-16 07:37 UTC · at c0f5db23373739e8bed52cfeba92cbf1aba54479 · squash

This pull request spent 3 hours 4 minutes 7 seconds in the queue, including 1 hour 37 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64

@mergify mergify Bot added the queued label Jul 16, 2026
@mergify mergify Bot merged commit cd74192 into matrixorigin:main Jul 16, 2026
29 checks passed
@mergify mergify Bot removed the queued label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Logservice leaks NodeHost and workers when metadata or replica initialization fails

3 participants